<template>
	<view v-if="!successful">
		<form report-submit='true'>
			<view class="payment-top acea-row row-column row-center-wrapper">
				<span class="name">{{$t('users.payment.money')}}</span>
				<view class="pic">
					$<span class="pic-font">{{ userinfo.now_money || 0 }}</span>
				</view>
			</view>
			<view class='merchantsSettled'>
				<view class='list'>
					<view class='input' style="width: 100%;"><text>$</text><input placeholder="0.00" type='number' placeholder-class='placeholder' v-model="money"
						 name="number"></input></view>
					<view class="item">
						
						<radio-group name="receipt_title_type" @change="changeHeader">
							<view class="acea-row row-middle">
							<label style="width: 100%;">
								<text>USDT{{$t('users.money.withdrawal')}}</text><radio value="1" checked style="float: right;"/>
							</label>
							</view>
							<view class="acea-row row-middle">
							<label style="width: 100%;margin-top: 18rpx;">
								<text>{{$t('users.payment.bankNumber')}}{{$t('users.money.withdrawal')}}{{$t('users.payment.money')}}</text><radio value="2" style="float: right;" />
							</label>
							</view>
						</radio-group>
					</view>
					<view class="item" v-if="isUsdt">
						<view class="acea-row row-middle">
							<!-- <i class="icon iconfont icon-qiye"></i> -->
							<text class="item-name">USDT{{$t('users.payment.mainNet')}}</text>
							<input type="text" maxlength="30" :placeholder="'USDT'+$t('users.payment.mainNet')" v-model="usdt_main" @input="validateBtn"
							 placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item" v-if="isUsdt">
						<view class="acea-row row-middle">
							<!-- <i class="icon iconfont icon-yonghu3"></i> -->
							<text class="item-name">USDT{{$t('users.payment.moneyAddr')}}</text>
							<input type="text" :placeholder="'USDT'+$t('users.payment.moneyAddr')" v-model="usdt_addr" @input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item" v-if="isBank">
						<view class="acea-row row-middle">
							<!-- <i class="icon iconfont icon-shoujihao"></i> -->
							<text class="item-name">{{$t('users.payment.bankNumber')}}</text>
							<input type="text" :placeholder="$t('users.payment.bankNumber')" v-model="bank_number" @input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item" v-if="isBank">
						<view class="acea-row row-middle">
							<!-- <i class="icon iconfont icon-shoujihao"></i> -->
							<text class="item-name">{{$t('users.payment.bangName')}}</text>
							<input type="text" :placeholder="$t('users.payment.bangName')" v-model="bank_bankName" @input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item" v-if="isBank">
						<view class="acea-row row-middle">
							<!-- <i class="icon iconfont icon-shoujihao"></i> -->
							<text class="item-name">{{$t('users.payment.userName')}}</text>
							<input type="text" :placeholder="$t('users.payment.userName')" v-model="bank_name" @input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
		
					<button class='submitBtn' :class="validate === true ? 'on':''" @click="formSubmit">{{$t('store.submit')}}</button>

				</view>
			</view>
		</form>
		<view class='loadingicon acea-row row-center-wrapper' v-if="loading">
			<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>
		</view>
		<!-- #ifdef MP -->
		<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
		<!-- #endif -->
	</view>
	<view class="settledSuccessMain" v-else>
		<view class="settledSuccessful">
			<image class="image" src="/static/images/settledSuccessful.svg" alt="">
			<view class="title">{{$t('users.money.succ')}}</view>
			<view class="info">{{$t('users.money.check')}}</view>
			<view class="goHome" hover-class="none" @click="goHome">
				{{$t('store.home')}}
			</view>
		</view>
	</view>
</template>
<script>
	// +----------------------------------------------------------------------
	// | CRMEB [ CRMEB赋能开发者，助力企業发展 ]
	// +----------------------------------------------------------------------
	// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
	// +----------------------------------------------------------------------
	// | Licensed CRMEB並不是自由软件，未经许可不能去掉CRMEB相關版权
	// +----------------------------------------------------------------------
	// | Author: CRMEB Team <admin@crmeb.com>
	// +----------------------------------------------------------------------
	import {
		HTTP_REQUEST_URL
	} from '@/config/app';
	import {
		getconfig,
	} from '@/api/public.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		withdraw,
		spreadInfo,
		getlastRecharge,
	} from "@/api/user";
	import {
		mapGetters
	} from "vuex";
	// #ifdef MP
	import authorize from '@/components/Authorize';
	// #endif
	let bok = true
	const app = getApp();
	export default {
		components: {
			// #ifdef MP
			authorize,
			// #endif
		},
		data() {
			return {
				usdt_main: '', 
				usdt_addr: '',
				money:'',
				bank_number: '', 
				bank_bankName: '', 
				bank_name: '',
				isBank: false,
				isUsdt: true,
				recharType:1,
				userinfo:{},
				loading: false,
				validate: false,
				successful: false,
				isLogin:false,
			};
		},
		beforeDestroy() {
			clearTimeout(this.timer)
		},
		// computed: mapGetters(['isLogin']),
		onLoad(options) {
			console.log(options)
			this.isLogin = this.$store.getters.isLogin()
			if (this.isLogin) {
			} else {
				// #ifdef H5 || APP-PLUS
				toLogin();
				// #endif 
				// #ifdef MP
				this.isAuto = true;
				this.$set(this, 'isShowAuth', true)
				// #endif
			}
			if (options.mer_i_id) {
				this.mer_i_id = options.mer_i_id
				uni.showLoading({
					title: thsi.$t('store.get.data'),
				});
				this.$nextTick(function() {
					this.getGoodsDetails(options.mer_i_id)
				})
			}
		},
		onShow: function() {
			let that = this;
			if (that.isLogin) {
				this.getUserInfo();
			} else {
				// #ifdef H5 || APP-PLUS
				toLogin();
				// #endif
				// #ifdef APP-PLUS
				this.userInfo = {}
				// #endif
			}
		},
		onReady() {
			uni.$on('update',(data)=>{
				this.protocol = data.sys_intention_agree
			})
		},
		methods: {
			changeHeader(e) {
				console.log(e);
				if (e.detail.value == 1) {
					this.recharType=1;
					this.isUsdt = true;
					this.isBank = false;
				}else{
					this.recharType=2;
					this.isUsdt = false;
					this.isBank = true;
				}
			},
			goTo(){
				window.location.href = HTTP_REQUEST_URL+'/merchant/login?redirect=%2Fmerchant%2Fconfig%2Fservice';
			},
			getConfig() {
				this.isType = false;
				this.showProtocol = true;
				// 获取配置
				getconfig().then(res => {
					this.protocol = app.globalData.sys_intention_agree
				}).catch(err => {})
			},
			/**
			 * 获取個人用户資訊
			 */
			getUserInfo: function() {
				let that = this;
				spreadInfo().then(res => {
					that.$set(that, 'userinfo', res.data);
				})
				getlastRecharge().then(res => {
					console.log(res);
					that.usdt_main = res.data.usdt_main;
					that.usdt_addr = res.data.usdt_addr;
					that.bank_number = res.data.bank_number;
					that.bank_bankName = res.data.bank_bankName;
					that.bank_name = res.data.bank_name;
				});
			},
			toggleTab(str) {
				this.$refs[str].show();
			},
			// 首頁
			goHome() {
				uni.navigateTo({
					url: "/pages/users/user_money/index"
				})
			},
			formSubmit: function(e) {
				let that = this;
				if (that.validateForm() && that.validate) {
					let requestData = {
						usdt_main: that.usdt_main,
						usdt_addr: that.usdt_addr,
						money:that.money,
						bank_account:that.bank_number,
						bank_name: that.bank_bankName,
						bank_username: that.bank_name,
						recharType:that.recharType
					}
					console.log('创建', requestData)
					withdraw(requestData).then(data => {
							if (data.status == 200) {
								that.$util.Tips({
									title: this.$t('users.money.tx.succ')
								});
								
								that.loading = true;
								this.timer = setTimeout(() => {
									that.successful = true;
								}, 1000)
							}

					}).catch(res => {
							that.$util.Tips({
								title: res
							});
						})
				}
			},
			validateBtn: function() {
			},
			validateForm: function() {
				let that = this
				console.log(that.money);
				if (parseFloat(that.money) < 0 || parseFloat(that.money) == NaN || that.money == undefined || that.money == "") {
					return that.$util.Tips({
						title: this.$t('users.payment.enter')+this.$t('users.payment.enterMoney')
					});
				}
				if (!that.usdt_main&&that.recharType==1) return that.$util.Tips({
					title: this.$t('users.payment.enter')+'USDT'+this.$t('users.payment.mainNet')
				});
				if (!that.usdt_addr&&that.recharType==1) return that.$util.Tips({
					title: this.$t('users.payment.enter')+'USDT'+this.$t('users.payment.moneyAddr')
				});
				if (!that.bank_number&&that.recharType==2) return that.$util.Tips({
					title: this.$t('users.payment.enter')+this.$t('users.payment.bankNumber')
				});
				if (!that.bank_bankName&&that.recharType==2) return that.$util.Tips({
					title: this.$t('users.payment.enter')+this.$t('users.payment.bangName')
				});
				if (!that.bank_name&&that.recharType==2) return that.$util.Tips({
					title: this.$t('users.payment.enter')+this.$t('users.payment.userName')
				});
				that.validate = true;
				return true;
			},
			jumpToList() {
				uni.navigateTo({
					url: "/pages/store/applicationRecord/index"
				})
			},

		}
	}
</script>

<style scoped lang="scss">
	.uni-input-placeholder {
		color: #B2B2B2;
	}
	.item-name{
		width: 190rpx;
	}
	.merchantsSettled .list .input {
		display: flex;
		align-items: center;
		justify-content: center;
		border-bottom: 1px dashed #dddddd;
		margin: 60rpx auto 0 auto;
		padding-bottom: 20rpx;
		font-size: 56rpx;
		color: #333333;
		flex-wrap: nowrap;
	
	}
	
	.merchantsSettled .list .input text {
		padding-left: 106rpx;
	}
	
	.merchantsSettled .list .input input {
		padding-right: 106rpx;
		width: 300rpx;
		height: 94rpx;
		text-align: center;
		font-size: 70rpx;
	}
	.payment-top {
		width: 100%;
		height: 350rpx;
		background-color: #002EA6;

		.name {
			font-size: 26rpx;
			color: rgba(255, 255, 255, 0.8);
			margin-top: -38rpx;
			margin-bottom: 30rpx;
		}

		.pic {
			font-size: 32rpx;
			color: #fff;
		}

		.pic-font {
			font-size: 78rpx;
			color: #fff;
		}
	}
	.uni-list-cell {
		position: relative;

		.iconfont {
			font-size: 14px;
			color: #7a7a7a;
			position: absolute;
			right: 15px;
			top: 7rpx;
		}
		.icon-guanbi2{
			right: 35px;
		}
	}
	
	.merchantsSettled {
		background: linear-gradient(#002EA6 0%, #FFE78F 100%);
		height: 80vh;
	}

	.merchantsSettled .merchantBg {
		width: 750rpx;
		width: 100%;
	}

	.merchantsSettled .list {
		background-color: #fff;
		border-radius: 12px;
		padding: 22px 0;
		margin: 0 15px;
		position: absolute;
		top: 300rpx;
		// margin-top: -160px;
		width: calc(100% - 30px);
	}

	.application-record {
		position: absolute;
		display: flex;
		align-items: center;
		top: 240rpx;
		right: 0;
		color: #fff;
		font-size: 22rpx;
		background-color: rgba(0, 0, 0, 0.3);
		padding: 8rpx 18rpx;
		border-radius: 20px 0px 0px 20px;
	}

	.merchantsSettled .list .item {
		padding: 50rpx 0 20rpx;
		border-bottom: 1rpx solid #eee;
		position: relative;
		margin: 0 20px;

		&.no-border {
			border-bottom: none;
			padding-left: 0;
			padding-right: 0;
		}

		.item-title {
			color: #666666;
			font-size: 28rpx;
			display: block;
		}

		.item-desc {
			color: #B2B2B2;
			font-size: 22rpx;
			display: block;
			margin-top: 9rpx;
			line-height: 36rpx;
		}
	}

	.acea-row,
	.upload {
		display: -webkit-box;
		display: -moz-box;
		display: -webkit-flex;
		display: -ms-flexbox;
		display: flex;
		-webkit-box-lines: multiple;
		-moz-box-lines: multiple;
		-o-box-lines: multiple;
		-webkit-flex-wrap: wrap;
		-ms-flex-wrap: wrap;
		flex-wrap: wrap;
	}

	.upload {
		margin-top: 20rpx;
	}

	.acea-row.row-middle {
		-webkit-box-align: center;
		-moz-box-align: center;
		-o-box-align: center;
		-ms-flex-align: center;
		-webkit-align-items: center;
		align-items: center;
		padding-left: 2px;
	}

	.acea-row.row-column {
		-webkit-box-orient: vertical;
		-moz-box-orient: vertical;
		-o-box-orient: vertical;
		-webkit-flex-direction: column;
		-ms-flex-direction: column;
		flex-direction: column;
	}

	.acea-row.row-center-wrapper {
		-webkit-box-align: center;
		-moz-box-align: center;
		-o-box-align: center;
		-ms-flex-align: center;
		-webkit-align-items: center;
		align-items: center;
		-webkit-box-pack: center;
		-moz-box-pack: center;
		-o-box-pack: center;
		-ms-flex-pack: center;
		-webkit-justify-content: center;
		justify-content: center;
	}

	.merchantsSettled .list .item .pictrue {
		width: 130rpx;
		height: 130rpx;
		margin: 24rpx 22rpx 0 0;
		position: relative;
		font-size: 11px;
		color: #bbb;

		&:nth-child(4n) {
			margin-right: 0;
		}

		&:nth-last-child(1) {
			border: 0.5px solid #ddd;
			box-sizing: border-box;
		}


		uni-image,
		image {
			width: 100%;
			height: 100%;
			border-radius: 1px;

			img {
				-webkit-touch-callout: none;
				-webkit-user-select: none;
				-moz-user-select: none;
				display: block;
				position: absolute;
				top: 0;
				left: 0;
				opacity: 0;
				width: 100%;
				height: 100%;
			}
		}

		.icon-guanbi1 {
			font-size: 33rpx;
			position: absolute;
			top: -10px;
			right: -10px;
		}
	}
	.uni-list-cell-db{
		position: relative;
	}
	.wenhao{
		width: 34rpx;
		height: 34rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		border-radius: 50%; 
		background: #E3E3E3;
		color: #ffffff!important;
		margin-left: 4rpx;
		position: absolute;
		left: 122rpx;
	}
	.merchantsSettled .list .item .imageCode {
		position: absolute;
		top: 7px;
		right: 0;
	}

	.merchantsSettled .list .item .icon {
		font-size: 40rpx;
		color: #b4b1b4;
	}

	.merchantsSettled .list .item input {
		width: 400rpx;
		font-size: 30rpx;
		// margin-left: 30px;
	}
	.merchantsSettled .list .item .placeholder {
		color: #b2b2b2;
	}
	.merchantsSettled .default {
		padding: 0 30rpx;
		height: 90rpx;
		background-color: #fff;
		margin-top: 23rpx;
	}
	.merchantsSettled .default checkbox {
		margin-right: 15rpx;
	}
	.merchantsSettled .acea-row uni-image {
		width: 20px;
		height: 20px;
		display: block;
	}
	.merchantsSettled .list .item .codeIput {
		width: 125px;
	}
	.uni-input-input {
		display: block;
		height: 100%;
		background: none;
		color: inherit;
		opacity: 1;
		-webkit-text-fill-color: currentcolor;
		font: inherit;
		line-height: inherit;
		letter-spacing: inherit;
		text-align: inherit;
		text-indent: inherit;
		text-transform: inherit;
		text-shadow: inherit;
	}
	.merchantsSettled .list .item .code {
		position: absolute;
		width: 93px;
		line-height: 27px;
		border: 1px solid #E93323;
		border-radius: 15px;
		color: #E93323;
		text-align: center;
		bottom: 8px;
		right: 0;
		font-size: 12px;
	}
	.merchantsSettled .list .item .code.on {
		background-color: #bbb;
		color: #fff;
		border-color: #bbb;
	}
	.merchantsSettled .submitBtn {
		width: 588rpx;
		margin: 0 auto;
		height: 86rpx;
		border-radius: 25px;
		text-align: center;
		line-height: 86rpx;
		font-size: 15px;
		color: #fff;
		background: red;
		margin-top: 25px;
	}
	.merchantsSettled .submitBtn.on {
		background: #E93323;
	}
	uni-checkbox-group,
	.settleAgree {
		display: inline-block;
		font-size: 24rpx;
	}
	uni-checkbox-group {
		color: #b2b2b2;
	}
	.settleAgree {
		color: #E93323;
		position: relative;
		top: 2px;
		left: 8px;
	}
	.merchantsSettled uni-checkbox .uni-checkbox-wrapper {
		width: 30rpx;
		height: 30rpx;
		border: 2rpx solid #C3C3C3;
		border-radius: 15px;
	}
	.settlementAgreement {
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		background: rgba(0, 0, 0, .5);
		z-index: 10;
	}
	.settlementAgreement .setAgCount {
		background: #fff;
		width: 656rpx;
		height: 458px;
		position: absolute;
		top: 50%;
		left: 50%;
		border-radius: 12rpx;
		-webkit-border-radius: 12rpx;
		padding: 52rpx;
		-webkit-transform: translate(-50%, -50%);
		-moz-transform: translate(-50%, -50%);
		transform: translate(-50%, -50%);
		overflow: hidden;
		.content {
			height: 900rpx;
			overflow-y: scroll;

			::v-deep p {
				font-size: 13px;
				line-height: 22px;
			}

			::v-deep img {
				max-width: 100%;
			}
		}
	}
	.settlementAgreement .setAgCount .icon {
		font-size: 42rpx;
		color: #b4b1b4;
		position: absolute;
		top: 15rpx;
		right: 15rpx;

	}
	.settlementAgreement .setAgCount .title {
		color: #333;
		font-size: 32rpx;
		text-align: center;
		font-weight: bold;
	}
	.settlementAgreement .setAgCount .content {
		margin-top: 32rpx;
		color: #333;
		font-size: 26rpx;
		line-height: 22px;
		text-align: justify;
		text-justify: distribute-all-lines;
		height: 756rpx;
		overflow-y: scroll;
	}
	.settledSuccessMain {
		height: 100vh;
		display: flex;
		flex-direction: column;
		background: #fff;
	}
	.settledSuccessful {
		flex: 1;
		width: 100%;
		padding: 0 56px;
		height: auto;
		background: #fff;
		text-align: center;
	}
	.settledSuccessful .image {
		width: 189px;
		height: 157px;
		margin-top: 66px;
	}
	.settledSuccessful .title {
		color: #333333;
		font-size: 16px;
		font-weight: bold;
		margin-top: 35px;
	}
	.settledSuccessful .info {
		color: #A0A0A0;
		font-size: 13px;
		margin-top: 12px;
	}
	.settledSuccessful .goHome {
		margin: 60px auto 0;
		line-height: 43px;
		color: #282828;
		font-size: 15px;
		border: 1px solid #B4B4B4;
		border-radius: 60px;
	}
	::v-deep uni-checkbox .uni-checkbox-input {
		width: 15px;
		height: 15px;
		position: relative;
	}
	::v-deep uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked:before {
		font-size: 14px;
	}
	.loadingicon {
		height: 100vh;
		overflow: hidden;
		position: absolute;
		top: 0;
		left: 0;
	}
	.icon-xiangyou {
		font-size: 22rpx;
	}
	// #ifdef MP
	checkbox-group {
		display: inline-block;
	}
	// #endif
	.setAgCount{
		::v-deep table{
			border:  1rpx solid #DDD;
			border-bottom: none;
			border-right: none;
		}
		::v-deep td, th {
		    padding: 5rpx 10rpx;
		    border-bottom: 1rpx solid #DDD;
			border-right:  1rpx solid #DDD;
		}
	}
	
</style>
